from .util import NamedFieldStruct, UnicodeFieldStruct
from .constant import NAME_MAX

Offset = 'q'
Blkno = 'q'
Ino = 'q'
Type = 'B'
Perms = 'H'
Time = 'Q'
Blksize = 'Q'
Depth = 'B'

BootRecord = NamedFieldStruct(
    'BootRecord', [
        ("fsident", '32s'),
        ("blkcount", Blkno),
        ("blksize", Blksize),
        ("serial", 'I'),
    ], 52)
#assert BootRecord.size == 52

Data = NamedFieldStruct(
    'Data', [
        ("size", Offset),
        ("root", Blkno),
        ("depth", Depth),
    ], 24)

Inode = NamedFieldStruct(
    'Inode', [
        ("ino", Ino),
        ("type", Type),
        ("perms", Perms),
        ("nlink", 'i'),
        ("uid", 'I'),
        ("gid", 'I'),
        ("rdev", 'Q'),
        ("atime", Time),
        ("mtime", Time),
        ("ctime", Time),
        ("data", Data),
    ], 80)

Dirent = NamedFieldStruct(
    'Dirent', [
        ("ino", Ino),
        ('name', UnicodeFieldStruct(NAME_MAX, 'utf-8')),
        #('name', '{}s'.format(NAME_MAX)),
        ("type", Type),
    ], 264)
